package com.zto.sch.base.normal;

import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2020-12-25 18:09
 **/
public class CurrentHashMapTest {
    public static void main(String[] args) {
        // 创建一个 HashMap
        ConcurrentHashMap<String, Integer> prices = new ConcurrentHashMap<>();

        // 往HashMap中添加映射关系
        prices.put("Shoes", 200);
//        prices.put("Bag", 300);
//        prices.put("Pant", 150);
        System.out.println("HashMap: " + prices);

        // 重新计算鞋加上10%的增值税后的价值
//        int shoesPrice = prices.computeIfPresent("Shoes", (key, value) -> value + value * 10/100);
        Integer shoesPrice = prices.computeIfPresent("Shoes", (key, value) -> {
            System.out.println(key + "::" + value);
            return null;
        });
        System.out.println("Price of Shoes after VAT: " + shoesPrice);

        // 输出更新后的HashMap
        System.out.println("Updated HashMap: " + prices);
        System.out.println("size: " + prices.size());
    }
}
